package cn.laixueit.base;

import cn.hutool.http.HttpStatus;

import java.util.HashMap;

/**
 * @author duxiang
 * @date 2023/11/27 11:11
 */

public class R extends HashMap<String, Object> {

    R() {
        put("code", 0);
        put("msg", "success");
    }

    public static R ok() {
        R r = new R();
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put("msg", msg);
        return r;
    }

    public static R error() {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, "Internal Server Error.");
    }

    public static R error(String msg) {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
